package com.yunhe.springbootdemo3.service.impl;

import com.yunhe.springbootday1.dao.AccountDao;
import com.yunhe.springbootday1.domain.Account;
import com.yunhe.springbootday1.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AccountServiceImpl1 implements AccountService {

    @Autowired
    private AccountDao accDao;

    /**
     * 注册业务
     * @param account
     * @return
     */
    @Override
    public boolean reg(Account account) {

        //调用持久层用户信息添加功能
        int i = accDao.addAccount(account);

        if(i>0){
            return true;
        }else{
            return false;
        }

    }

    /**
     * 验证账号是否存在
     * @param username
     * @return
     */
    @Override
    public boolean checkUsername(String username) {

        String password = accDao.findPasswordByUsername(username);

        /*
            查询到信息，则表示账号存在返回false
         */
        if(password!=null){
            return false;
        }

        return true;
    }

    /**
     * 登录业务方法
     *
     * @param username
     * @param password
     * @return
     */
    @Override
    public Account login(String username, String password) {

        //调用持久层查询方法
        Account account = accDao.findAccountByUsernameAndPassword(username,password);

      return account;
    }
}
